package daobeauty.interceptor.invoke.impl;

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import daobeauty.interceptor.invoke.InvokeStrategy;
import daobeauty.util.MethodSignatureUtils;

public class GetConstantObjectInvoke implements InvokeStrategy {
	private static final Log LOG = LogFactory.getLog(GetConstantObjectInvoke.class);
	
	private final Object object;
	
	public GetConstantObjectInvoke(Method method, Object object) {
		super();
		if (LOG.isInfoEnabled()){
			LOG.info("method: "+method+", object: "+object);
		}
		final Class [] parameterTypes = method.getParameterTypes();
		if (parameterTypes!=null && parameterTypes.length>0){
			throw new IllegalArgumentException("method "+MethodSignatureUtils.toMethodSignature(method)+" must have no parameters.");
		}
		this.object = object;
		if (LOG.isInfoEnabled()){
			LOG.info("created getConstantObject strategy with object "+object.getClass().getName()+" for method "+MethodSignatureUtils.toMethodSignature(method));
		}
	}

	public Object invoke(String methodName, Object[] args) throws Exception{
		return object;
	}
}
